package com.CST.controller.zx;


import com.CST.common.api.ResultObject;
import com.CST.entity.zx.ZxDataentry;
import com.CST.entity.zx.ZxDatadict;
import com.CST.service.zx.IZxDatadictService;
import com.CST.service.zx.IZxDataentryService;
import com.CST.util.PageHelperTool;
import io.swagger.annotations.*;

import java.util.*;

import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ly
 * @since 2023-02-23
 */
@Api(tags = {"系统设置，对数据字典的操作"})
@RestController
@RequestMapping("/zxDatadict")
public class ZxDatadictController {

    @Autowired
    private IZxDatadictService targetService;
    @Autowired
    private IZxDataentryService iZxDataentryService;


    @PostMapping("/save")
    @ApiOperation("新建数据字典")
    @ApiImplicitParams(@ApiImplicitParam(value = "zxDatadict",required = true))
    public ResultObject<String> save(@RequestBody ZxDatadict zxDatadict) {
        return targetService.addZxDatadict(zxDatadict);
    }

    @PostMapping("/update")
    @ApiOperation("编辑数据字典")
    @ApiImplicitParams(@ApiImplicitParam(value = "zxDatadict",required = true))
    public ResultObject<String> saveOrUpdate(@RequestBody ZxDatadict ZxDatadict) {
        return targetService.updateZxDatadict(ZxDatadict);
    }


    @PostMapping("/page")
    @ApiOperation("分页查询数据字典,查询按钮也绑定这个")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "pageNo",required = true),
            @ApiImplicitParam(value = "pageSize",required = true),
            @ApiImplicitParam(value = "dictName",required = false)
    })
    public ResultObject page(@RequestBody ZxDatadict zxDatadict) {
//        return targetService.getById(id);
        List<ZxDatadict> zxDatadicts = targetService.pageList(zxDatadict);
        return ResultObject.successReturn(
                PageHelperTool.excutePageInfo(zxDatadicts, zxDatadict.getPageNo(), zxDatadict.getPageSize()));
    }

}

